package com.atguigu.gmall.gateway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author: atguigu
 * @create: 2023-08-03 10:46
 */
@Slf4j
@Component
public class AccessFilter implements GlobalFilter, Ordered {

    @Value("${server.port}")
    private Integer port;

    /**
     * 验证请求是否经过该节点
     *
     * @param exchange
     * @param chain
     * @return
     */
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        log.info("[网关被访问]，当前节点端口：{}", port);
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return -1;
    }
}
